package com.orangelife.arenasdk.util;

import android.util.Log;

import java.util.Comparator;
import java.util.Map;
import java.util.TreeMap;

/**
 * <p>
 * Created by 吴格非 on 2016-10-9.
 * <p>
 *
 * @author 吴格非
 * @since v1.0.0
 */

public class EncryptionUtil {

    public static String encrypt(String crypto, Map<String, Object> params) throws Exception {
        if (crypto == null) {
            return null;
        }
        String sign = SignUtil.genSign(params);
        params.put("sign", sign);
        String result = toStringResult(params);
        return AesUtil.encrypt(crypto, result);
    }

    private static String toStringResult(Map<String, Object> params) {
        StringBuilder sb = new StringBuilder();

        for (String key : params.keySet()) {
            if (sb.length() > 0) {
                sb.append('&');
            }
            sb.append(key);
            sb.append('=');
            sb.append(params.get(key));
        }
        Log.e(EncryptionUtil.class.getSimpleName(), "toString=" + sb.toString());
        return sb.toString();
    }


}
